package com.lovemanai.taglib;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.SimpleTagSupport;


public class DynaAttributesTag extends SimpleTagSupport implements DynamicAttributes {

	//保存每个属性名
	private ArrayList<String> keys = new ArrayList<String>();
	//保存每个属性值
	private ArrayList<Object> values = new ArrayList<Object>();
	
	@Override
	public void setDynamicAttribute(String uri, String localName, Object value)
			throws JspException {
		//添加属性名
		keys.add(localName);
		//添加属性值
		values.add(value);
		
	}

	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		out.println("<ol>");
		for (int i = 0; i < keys.size(); i++) {
			out.println("<li>" + keys.get(i) + "  " + values.get(i) + "</li>");
		}
		out.println("</ol>");
	}
	
	
}
